home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / access / secure.zip / SRC / SECURE.C < prev   
C/C++ Source or Header  |  1991-11-23  |  5KB  |  192 lines

  1.  
  2. /* **********  SECURE Lan Manager security checking for SQL Server *******
  3. *
  4. * This program is an adaptation of the standard pass-through gateway.
  5. * It implements a security integration layer between Lan Manager
  6. * and SQL Server.  On as connection event (in SECURECBS.C) Lan Manager
  7. * is queried for the name of the user on the other end of the pipe.
  8. * This username is compared to the requested SQL Server login name,
  9. * and the login is rejected if the two don't match.
  10. *
  11. * If the /F flag is given at startup, all language events will be written
  12. * to the GDK log file prior to being passed on to SQL Server.
  13. * The /N flag turns off userid checking.
  14. *
  15. * This application requires the LAN Manager 2.0 Programmer's Toolkit
  16. * for compilation and linking.
  17. *
  18. ***********************************************************************/
  19.  
  20.  
  21.  
  22. #include    <stdlib.h>
  23. #include    <stdio.h>
  24. #include    <string.h>
  25.  
  26. #define INCL_BASE
  27. #include    <OS2.h>
  28.  
  29. #include    <sqlfront.h>
  30. #include    <sqldb.h>
  31.  
  32. #include    <srv.h>
  33.  
  34.  
  35. // Globals
  36. //
  37. DBCHAR    FAR *GDKsrvrname = "";  // The default remote server name
  38. DBCHAR    FAR *GDKpipename = TDS34_CONNECT_NAME;    // Default pipe name
  39.  
  40. DBCHAR    FAR *GDKlogfile = "gateway.log";
  41. BOOL fLogEnabled = FALSE;     // request logging off by default
  42. BOOL fConnectCheck = TRUE;    // LM connection verification on by default
  43.  
  44. // function prototypes
  45. //
  46. void getargs(int argc, char **argv );
  47.  
  48. void main( int argc, char **argv );
  49.  
  50. int    SRVAPI init_server    ( SRV_SERVER FAR * server );
  51.  
  52. void    SRVAPI set_remote_server_name ( char FAR * name );
  53.  
  54. // New function for setting options
  55. void    SRVAPI set_security_options ( BOOL logflag, BOOL checkflag );
  56.  
  57. int    chk_err      ( SRV_SERVER FAR * server,
  58.                SRV_PROC   FAR * srvproc,
  59.                int        srverror,
  60.                BYTE        severity,
  61.                BYTE        state,
  62.                int        oserrnum,
  63.                DBCHAR      FAR * errtext,
  64.                int        errtextlen,
  65.                DBCHAR      FAR * oserrtext,
  66.                int        oserrtextlen );
  67.  
  68. DBCHAR    FAR * getservername( int argc, char * argv[] );
  69.  
  70. DBCHAR FAR * getpipename(int argc, char* argv[]);
  71.  
  72. void main(argc, argv)
  73. int    argc;
  74. char    *argv[];
  75. {
  76.     SRV_CONFIG    FAR *config;        // The GDK configuration structure
  77.     SRV_SERVER    FAR *server;        // The GDK service process
  78.  
  79.     //    Read any command line arguments.
  80.     //
  81.     getargs(argc, argv);
  82.  
  83.     //    Send the name retrieved to the gateway's DLL module
  84.     //
  85.     set_remote_server_name( GDKsrvrname );
  86.  
  87.     //    Set the logging and security checking flags
  88.     //
  89.     set_security_options( fLogEnabled, fConnectCheck );
  90.  
  91.     //    Allocate a configuration structure that is used to initialize
  92.     //    the GDK application
  93.     //
  94.     config = srv_config_alloc();
  95.  
  96.     //    Allow 20 connections at a time.
  97.     //
  98.     srv_config( config, (DBINT)SRV_CONNECTIONS, "20", SRV_NULLTERM );
  99.  
  100.     //    Set the log file.
  101.     //
  102.     srv_config( config, (DBINT)SRV_LOGFILE, GDKlogfile, SRV_NULLTERM );
  103.  
  104.     //    Install the GDK error handler.
  105.     //
  106.     srv_errhandle( chk_err );
  107.  
  108.     //    Initialize the gateway GDK and save the server handle
  109.     //    so it can be used in later functions.
  110.     //
  111.     server = srv_init( config, GDKpipename, SRV_NULLTERM );
  112.  
  113.     if( server == NULL )
  114.     {
  115.     printf( "Unable to initialize GDK.  Check log file.\n" );
  116.     DosExit( EXIT_PROCESS, 1 );
  117.     }
  118.  
  119.     // When starting the gateway, initialize the remote server structure.
  120.     // This is done in the init_server() function.
  121.     // All the other event handlers are also defined in the init_server()
  122.     // function.
  123.     //
  124.     srv_handle(server, (DBINT)SRV_START, init_server);
  125.  
  126.     //    Now everything's ready to go with our GDK, so we
  127.     //    start it and keep it going until we get a stop request.
  128.     //
  129.     srv_log( server, FALSE, " ", SRV_NULLTERM );    // insert blank line
  130.     srv_log( server, TRUE,  "SECURE Starting", SRV_NULLTERM );
  131.  
  132.     printf( "\nSECURE Starting\n");
  133.  
  134.     srv_run(server);
  135.  
  136. }
  137.  
  138.  
  139. //  GETARGS - getargs( argc, argv )
  140. //
  141. //  Read the command line arguments.
  142. //
  143. //  Inputs:
  144. //    argc - int (from "main" entry)
  145. //    argv - pointer to array of char pointers (from "main" entry)
  146. //
  147. //  Outputs:
  148. //      VOID
  149. //
  150. void getargs( int argc, char *argv[] )
  151. {
  152.  
  153.     int i;
  154.     char *ptr;
  155.  
  156.     for (i = 1; i < argc; ++i)
  157.     {
  158.         if (argv[i][0] != '-' && argv[i][0] != '/')
  159.         {
  160.         printf("Usage: secure [-S<server name> -p<pipe name> -F<log file> -N]\n");
  161.             exit(1);
  162.         }
  163.         ptr = argv[i];
  164.         switch (ptr[1])
  165.         {
  166.         case 'S':
  167.             GDKsrvrname = ptr+2;
  168.             break;
  169.             
  170.         case 'p':
  171.             GDKpipename = ptr+2;
  172.             break;
  173.  
  174.     case 'F':
  175.         fLogEnabled = TRUE;
  176.         if (argv[i][2] != NULL)
  177.         {
  178.          GDKlogfile = ptr+2;
  179.         }
  180.             break;
  181.  
  182.     case 'N':
  183.         fConnectCheck = FALSE;
  184.             break;
  185.  
  186.         default:
  187.         printf("Usage: secure [-S<server name> -p<pipe name> -F<log file> -N]\n");
  188.             exit(1);
  189.     }
  190.     }
  191. }
  192.